﻿
app.controller('SafetyPromiseController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.GetSafetyPromisePageList = function (model, page) {
        $scope.PageLoading = true;
        $scope.TeamList = [];
        $http({
            method: 'POST',
            url: '../SafetyPromise/GetSafetyPromisePageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.PageLoading = false;
                if (ret.Code == 100) {
                    $scope.DataList = ret.Data.Data;

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.AddSafetyPromise = function (model) {
        var files = document.getElementById("taskfile").files;
        var controllist = $("[name='RoleItem']");
        var roleIdlist = [];
        for (var i = 0; i < controllist.length; i++) {
            if (controllist[i].checked) {
                roleId = controllist[i].value;
                roleIdlist.push(roleId);
            }
        }
        if (roleId == null) {
            alertify.alert("请选择角色");
            return false;
        }
        model.RoleId = roleIdlist.join();
        $scope.LoadingMsg = "正在提交,请稍后...";
        $scope.Submiting = true;
        Upload.upload({
            method: 'POST',
            url: '../SafetyPromise/AddSafetyPromise',
            data: { 'model': model },
            file: files
        })
            .success(function (ret) {
                $scope.Submiting = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        window.location.href = "SafetyPromisePageList?page=1";
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.GetRoleList = function () {
        $scope.LoadingMsg = "页面加载中";
        $scope.RoleList = [];
        $http({
            method: 'POST',
            url: '../Organization/GetRoleList'
        }).success(function (ret) {
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.RoleList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

});